1. Field of the Invention
The invention pertains to the field of three dimensional (3D) graphics emulation. More particularly, it pertains to the determination of which pixels to show when some objects in a displayed image obscure others due to differences in apparent distance from the viewer.
2. Description of the Related Art
In a 3D scene, the objects that are nearer to the viewer may obscure the view of other objects, which are farther away. As the perspective of the viewer changes, or the objects move with respect to one another, the view of objects which are fully or partly obscured may also change. When a two-dimensional graphics system emulates a three-dimensional scene, the graphics system which generates the image must maintain image data for every potentially displayable object, but will only display the closest object when two or more objects occupy the same perceived line of sight. For this reason, graphics systems typically maintain distance information on each displayable object, so that they can determine which object in a particular part of the screen is nearest and should be displayed, and which objects will be obscured and therefore not displayed.
FIGS. 1a and 1b illustrate this principle by showing two images containing a rectangular object and a circular object which overlap each other. In FIG. 1a, circular object 2 appears in front of rectangular object 3, overlapping it in area 4. In FIG. 1b, rectangular object 13 appears in front of circular object 12, overlapping it in area 14. (Note: dotted lines are shown in the figures to illustrate the boundaries of the overlapped area, but would not appear in the actual image.) In FIG. 1a, overlap area 4 would be filled in with picture elements (pixels) depicting the circular object 2, while the pixels depicting rectangular object 3 would not be used in overlap area 4. Conversely, in FIG. 1b overlap area 14 would be filled in with pixels depicting rectangular object 13, while the pixels depicting circular object 12 would not be used in overlap area 14.
To determine which objects should be perceived as nearer, depth values are assigned to every pixel of every displayable object. Depth values represent the apparent relative distance of the object from some reference point, such as the viewer. If two or more displayable objects encompass the same pixel location in the image, only the pixel from the nearest object (smallest depth value) should be displayed. A pixel depth buffer is used to maintain depth information about every pixel in the image, describing the depth of the nearest perceived object at each pixel location.
The conventional approach to creating the depth buffer is to compare the depths of the various objects at every pixel location. Each displayable object has a separate depth value for every pixel encompassed by that object, with the depth value describing the relative depth, or apparent distance from the viewer, of the object at that pixel location. A depth comparison is performed for each pixel of the displayed image. If the pixel for the object under consideration (the current pixel) is closer than the pixel presently displayable at that location (the reference pixel), then the current pixel will replace the reference pixel and the current pixel""s depth value will go into the pixel depth buffer for that pixel location. If the reference pixel is closer than the current pixel, then the reference pixel will remain as the displayable pixel, and the reference pixel depth information will remain in the pixel depth buffer for that pixel location. After the pixels of all objects which could occupy each pixel location have been considered in this manner, each pixel referenced in the pixel depth buffer will represent the nearest perceived object at that particular pixel location, and that pixel will be the one to display.
Occasionally a programmer may wish to display something other than the nearest object, such as the farthest object. In such special effects situations, different pixels would win the comparison tests, but the basic technique of a pixel-by-pixel comparison is the same. Since the comparisons are performed on a pixel-by-pixel basis, there is a potential need to perform multiple comparisons for every pixel in the displayed image. As graphic images achieve increasingly higher resolution with more pixels per image, devoting this amount of computation solely to the decision of which objects to display can use up an excessive amount of processor and memory bandwidth, and can limit the throughput of the graphics processing system.
The invention includes a method of using a depth buffer that includes identifying a first pixel group with a first set of depth values and identifying a second pixel group with a second set of depth values. A first span is formed including the minimum and maximum depth values from the first set, and a second span is formed including the minimum and maximum depth values from the second set. The minimum and maximum values of the first span are compared with the minimum and maximum values of the second span. At least a portion of the first span or the second span is saved as a result of the comparison.